<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function times() {
				var d = document.getElementById('time').value;
				var Y = document.getElementById('nian').value;
				var getDays = new Date(d);
				var mo = getDays.getMonth();
				var de = getDays.getDate();
				var y = new Date('01/01');
				if(Y==''||Y==null){
					var c = getDays.getTime() - y.getTime();
						txt.innerHTML = ('今年的第' + (c / 86400000 + 1) + '天')
					    alert('不输入年份默认该为平年')
				}
				else if ( (Y %4!== 0||Y%100==0&&Y%400!==0)&&(d == '2/29' || d=='2.29') ) {
					txt.innerHTML = ('输入错误该年不是闰年')
				} else if((Y % 4 == 0 && Y % 100 != 0 || Y % 400 == 0)&&(d == '2/29' || d=='2.29')){
					var c = getDays.getTime() - y.getTime();
					txt.innerHTML = ('今年的第' + (c / 86400000 + 1) + '天')
				}
				else if ((Y % 4 == 0 && Y % 100 != 0 || Y % 400 == 0) && mo > 1) {
					var c = getDays.getTime() - y.getTime();
					txt.innerHTML = ('今年的第' + (c / 86400000 + 2) + '天')
				} else {
					var c = getDays.getTime() - y.getTime();
					txt.innerHTML = ('今年的第' + (c / 86400000 + 1) + '天')
				}

			}
		</script>
	</head>
	<body>
		<input type="text" name="" id="nian" value="" placeholder="输入年份" />
		<input type="text" name="" id="time" value="" placeholder="输入日期" />
		<input type="button" id="" value="输入日期获取该天是该年的第几天" onclick="times()" />
		<p id="txt"></p>
	</body>
</html>

